package com.leyou.trade.web;

import com.leyou.trade.dto.OrderDTO;
import com.leyou.trade.dto.OrderFormDTO;
import com.leyou.trade.entity.Order;
import com.leyou.trade.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author 付
 */
@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    //创建订单
    @PostMapping
    public ResponseEntity<Long> createOrder(@RequestBody OrderFormDTO orderFormDTO){
     Long orderid =orderService.createOrder(orderFormDTO);
    return ResponseEntity.status(HttpStatus.CREATED).body(orderid);
    }
    //根据id查询订单
    @GetMapping("/{id}")
    public ResponseEntity<OrderDTO>queryOrder(@PathVariable("id") Long orderid){
           Order order= orderService.getById(orderid);
           return ResponseEntity.ok(new OrderDTO(order));
    }
    /**
     * 根据id查询订单状态
     * @param orderId 订单id
     * @return 状态
     */
    @GetMapping("/status/{orderId}")
    public ResponseEntity<Integer> queryOrderStatus(@PathVariable("orderId") Long orderId){
        return ResponseEntity.ok(orderService.queryOrderStatus(orderId));
    }
}
